//
//  HistoryViewController.m
//  qdqts
//
//  Created by Centling on 14-6-9.
//  Copyright (c) 2014年 seas.cheng. All rights reserved.
//
#import "scanHistoryCell.h"
#import "QTHistoryViewController.h"
#import "searchHistoryCell.h"
#define historySegmentedLeftIndex 0
#define historySegmentedRightIndex 1


@interface QTHistoryViewController () 
//@property (nonatomic, strong) NSString *;
@end

@implementation QTHistoryViewController

@synthesize historySegment;
@synthesize firstTableView;
@synthesize secondTableView;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.title=@"历史记录";
    // Do any additional setup after loading the view from its nib.
    self.histoyArray = [NSMutableArray arrayWithObjects:@"洗衣机",@"电视机",@"bing",nil];
    historySegment.selectedSegmentIndex = 1;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma history tableview

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (historySegment.selectedSegmentIndex)
    {
        case historySegmentedLeftIndex:
        {
            return 3;
        }
            break;
        case historySegmentedRightIndex:
        {
            return 8;
        } 
            break;
        default:
            return 10;
            break;
    }
}

// Get the history array from file based on the different segment selected.
- (NSMutableArray *)loadHistoryRecord:(BOOL)historyType
{
    NSMutableArray *gotfrommodle = nil;
    return gotfrommodle;
}

// Customize Cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    switch (historySegment.selectedSegmentIndex) {
        case historySegmentedLeftIndex:
        {
            static NSString *searchCell = @"searchHistoryCell";
            searchHistoryCell *cell = (searchHistoryCell *)[tableView dequeueReusableCellWithIdentifier:searchCell];
            
            if (cell ==nil)
            {
                NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"searchHistoryCell" owner:self options:nil];
                cell = (searchHistoryCell *)[nibArray objectAtIndex:0];
            }
            cell.textLabel.text = @"First tableview";
            return cell;
        }
            break;
        
        case historySegmentedRightIndex:
        {
            static NSString *scanCell = @"scanCell";
            scanHistoryCell *cell = (scanHistoryCell *)[tableView dequeueReusableCellWithIdentifier:scanCell];
            
            if (cell ==nil) {
                NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"scanHistoryCell" owner:self options:nil];
                cell = (scanHistoryCell *)[nibArray objectAtIndex:0];
            }
            cell.productName.text = @"海尔电视";
            //_histoyArray objectAtIndex:[indexPath row]]).standardName;
            cell.scanTime.text = @"2012-02-03";
//            NSString *imageUrl=((StandardInfoList *)[_stdArray objectAtIndex:indexPath.row]).imageUrl;
//            NSURL *url=[NSURL URLWithString:[qsServerUrl stringByAppendingString:imageUrl==nil?@"":imageUrl]];
//            NSLog(@"imageURI:%@",url);
//            [cell.stdImage setImageWithURL:url];
            
            return cell;
        }
            break;
        default:
        {
            NSString *str = [NSString stringWithFormat:@"str%d", row];
            
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
            
            if (cell == nil) {
                
                cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:str];
                
            }
            cell.textLabel.text = @"Default tableview";
            return cell;
        }
        break;
    }
}

//Set the height of the cell
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{
    return 85;
}


- (IBAction)setSegmentedPressed:(id)sender {
    switch ([sender selectedSegmentIndex]) {
        case historySegmentedLeftIndex:
            firstTableView.hidden = NO;
            secondTableView.hidden = YES;
            [firstTableView reloadData];
            break;
        case historySegmentedRightIndex:
            firstTableView.hidden = YES;
            secondTableView.hidden = NO;
            [secondTableView reloadData];
            break;
        default:
            break;
    }
}

- (void)viewDidUnload
{
    [self setHistorySegment:nil];
    [self setFirstTableView:nil];
    [self setSecondTableView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.view addSubview:self.firstTableView];
    [self.view addSubview:self.secondTableView];
}



#pragma Jump from tableview -> product view

//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    List *tempprod = (List*)[self.Product_list.list objectAtIndex:indexPath.row];
//    if (tempprod == nil) {
//        return;
//    }
//    
//    ProductDetailViewController *productviewController=[[ProductDetailViewController alloc] init];
//    //productViewController *productviewController=[[productViewController alloc] init];
//    [self.hideTabbarDelegate hideTabbar];
//    
//    productviewController.puid = tempprod.puid;
//    productviewController.url = tempprod.filePath;
//    
//    [_pushViewDelegate pushViewController:(UITableViewController *)productviewController navBarItem:@""];
//    //[self.navigationController pushViewController:product animated:YES];
//    NSLog(@"%@",@"运行didSelectRowIndexPath");
//    
//    
//}

@end
